<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
  <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  <ul class="nav navbar-nav">
    <li class="<%= params[:controller].eql?('admin/dashboard') ? 'active' : 'inactive' %>">
      <%= link_to admin_dashboard_index_path do %>
        <i class="icon-home"></i>
        <%= t("typus.dashboard.title") %>
      <% end %>
    </li>

    <% admin_user.applications.each do |application| %>
      <%
        app_id, apps = application.parameterize, admin_user.application(application)
        if (params[:application] == app_id) || (@resource && apps.include?(@resource.model_name))
          klass = 'active'
        end
      %>

      <li class="dropdown <%= klass %>">
        <%= link_to "#", :class => "dropdown-toggle", "data-toggle" => "dropdown" do %>
          <%= t("typus.application.#{application.parameterize('_')}", default: application) %>
          <b class="caret"></b>
        <% end %>

        <ul class="dropdown-menu">
          <% admin_user.application(application).map(&:constantize).each do |klass| %>
            <% if klass.typus_options_for(:hide_from_dashboard) == false %>
              <li><%= link_to klass.model_name.human(count: 1_000), controller: "/admin/#{klass.to_resource}" %></li>
            <% end %>
          <% end %>
        </ul>
      </li>
    <% end %>
  </ul>

  <% if not admin_user.is_a?(FakeUser) %>
    <ul class="nav navbar-nav navbar-right" style="margin-right: 5px;">
      <ul class="nav navbar-nav navbar-right">
        <li class="dropdown" data-dropdown="dropdown">
          <%= link_to "#", :class => "dropdown-toggle", "data-toggle" => "dropdown" do %>
            <%= admin_user.to_label %>
            <b class="caret"></b>
          <% end %>

          <ul class="dropdown-menu">
            <li>
              <%= link_to url_for(admin_edit_user_path(admin_user)) do %>
                <span class="glyphicon glyphicon-user"></span>
                <%= t("typus.shared.settings") %>
              <% end %>
            </li>

            <li class="divider"></li>

            <% if Typus.link_to_help %>
              <li>
                <%= link_to '#' do %>
                  <span class="glyphicon glyphicon-info-sign"></span>
                  <%= t("typus.shared.help") %>
                <% end %>
              </li>
            <% end %>

            <li>
              <%= link_to admin_sign_out_path, :method => :delete do %>
                <span class="glyphicon glyphicon-off"></span>
                <%= t('typus.buttons.sign_out') %>
              <% end %>
            </li>
          </ul>
        </li>
      </ul>
    </ul>
  <% end %>

</div>
